<?php

###########################################################################
#   Copyright (C) 2012 CDNPAL LTD by Christopher Gu                       #
#   resources@cdnpal.com                                                  #
#                                                                         #
#   coded for Php 4.3/5.X and above                                       #
#   and AllowOverride all for .htaccess                                   #
#                                                                         #
#   This program is free software released                                #
#   under the GPL version 2 license:                                      #
#   http://www.gnu.org/licenses/gpl-2.0.htm                               #
#                                                                         #
#   This program is distributed WITHOUT ANY WARRANTY                      #
#   or FITNESS FOR A PARTICULAR PURPOSE.                                  #
#                                                                         #
#   DADF-SDK                                                              #
#                                                                         #
###########################################################################

class XMLService {

	public $doc = null;
	
	
	public function __construct($request_xml, $schema_name) {
		
		$this->doc = new DOMDocument();

		$success = $this->doc->loadXML($request_xml);

		if ($success == false || $this->doc->schemaValidate ('../application/schemas/' . $schema_name) == false):
			
			throw new Exception("DADF schema validation failed");
			
		endif;
		
	}
	
	public function get_node_children($node, $key) {
		
		return $node->getElementsByTagName($key) != null ? $node->getElementsByTagName($key) : array();
	}

	public function get_single_child($node, $key) {
		
		return empty($node->getElementsByTagName($key)->item(0)->nodeValue) ? null : trim($node->getElementsByTagName($key)->item(0)->nodeValue);
	}
	

	
}